using System;
using GameFramework.Event;
using UnityEngine;
using Unity.VisualScripting;

namespace LS.UGFUnits
{
    [UnitShortTitle("Close")]
    [UnitSurtitle("UI Form")]
    public sealed class CloseUIFormById : UIUnit
    {
        [DoNotSerialize]
        [PortLabelHidden]
        public ValueInput SerialId { get; private set; }
        
        protected override void Definition()
        {
            base.Definition();
            SerialId = ValueInput<int>(nameof(SerialId), 0);
            Succession(Input, Output);
        }

        protected override ControlOutput In(Flow flow)
        {
            int serialId = flow.GetValue<int>(SerialId);
            Target?.CloseUIForm(serialId);
            return base.In(flow);
        }
    }
}